import api from "@/util/api.js";
//查询
async function findall(pageNo = 1, pageSize = 10, params = {}) {

    let resp = await api({
        url: "/room",
        method: "get",
        params: {
            pageNo,
            pageSize,
            ...params
        }
    });
  
    sessionStorage.removeItem("pageNo");
    sessionStorage.removeItem("pageSize");
    sessionStorage.removeItem("total");
   
    sessionStorage.setItem("pageNo",resp.pi.pageNo);
    sessionStorage.setItem("pageSize",resp.pi.pageSize);
    sessionStorage.setItem("total",resp.pi.total);
    let data = resp.data;
    for (let i = 0; i < data.length; i++) {
        if (data[i].facility != null) {
            data[i].facilityName = data[i].facility.facilityName;
            delete data[i].facility;
            //console.log(data[i]);
        }
    }
    
    return data;
}
async function deletebyid(id){
    let resp= await api({
        url:"/room",
        method:"delete",
        data:id
    });
    return resp;
    }
 //新增
async function adduser(adminadd){
    let resp=await api({
        url:"/room",
        method:"post",
        data:adminadd
    })
    return resp;
}
//修改
async function updateuser(adminadd){
    let resp=await api({
        url:"/room",
        method:"put",
        data:adminadd
    })
    return resp;
}   
export { findall ,deletebyid,adduser,updateuser}